package cn.tedu.uep.petType.controller;

import cn.tedu.uep.base.response.JsonResult;
import cn.tedu.uep.petType.pojo.dto.PetTypeQuery;
import cn.tedu.uep.petType.pojo.dto.PetTypeSaveParam;
import cn.tedu.uep.petType.pojo.vo.PetTypeVO;
import cn.tedu.uep.petType.service.PetTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/pet")
public class PetTypeController {
    @Autowired
    private PetTypeService petTypeService;

    /*加载宠物种类列表*/
    @GetMapping("select")
    public JsonResult selectPetType(PetTypeQuery petTypeQuery){
        log.debug("加载宠物种类列表需要参数{}",petTypeQuery);
        List<PetTypeVO> list = petTypeService.selectPetType(petTypeQuery);
        return JsonResult.ok(list);
    }

    /*新增宠物种类*/
    @PostMapping("save")
    public JsonResult savePetType(PetTypeSaveParam petTypeSaveParam){
        log.debug("新增宠物种类参数{}",petTypeSaveParam);
        petTypeService.savePetType(petTypeSaveParam);
        return JsonResult.ok();
    }

    /*修改宠物种类*/
    @PostMapping("update")
    public JsonResult updatePetType(PetTypeSaveParam petTypeSaveParam){
        log.debug("修改宠物种类参数{}",petTypeSaveParam);
        petTypeService.savePetType(petTypeSaveParam);
        return JsonResult.ok();
    }

    /*删除宠物种类*/
    @PostMapping("delete/{petTypeId}")
    public JsonResult deletePetType(@PathVariable Integer petTypeId){
        log.debug("删除宠物种类参数{}",petTypeId);
        petTypeService.deletePetType(petTypeId);
        return JsonResult.ok();
    }
}
